package com.ktgj.flight.common.linkstar;

import com.ktgj.common.core.utils.IDCardUtil;
import com.ktgj.common.core.utils.xml.XElement;
import com.ktgj.flight.common.linkstar.domain.changeFlight.ChangeFlightRequest;
import com.ktgj.flight.common.linkstar.domain.publishprice.FlightPublishPriceReqVo;
import com.ktgj.flight.domain.InterfaceEntity.*;
import org.json.JSONObject;
import org.json.XML;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wyj
 * @create 2021-10-28 11:40
 */
public class LinkStarTest {
    public static void main(String[] args) throws ParseException {


        XElement root = new XElement();
        root  = XElement.loadXml("<OTA_AirBookRS>\n" +
                "    <AirReservation>\n" +
                "        <BookingReferenceID ID=\"HQ5X6W\" ID_Context=\"PNR\"/>\n" +
                "        <Comment>OK</Comment>\n" +
                "        <Comment>SUCCESS</Comment>\n" +
                "        <Comment>1</Comment>\n" +
                "    </AirReservation>\n" +
                "</OTA_AirBookRS>");
        if (root.toString().contains("Errors"))
        {
            System.out.println("===========");
        }

        LinkStar linkStar = new LinkStar();

        //查询航班
        MoFlightSearchRequest request = new MoFlightSearchRequest();

//
        //单程
        MoFlightSearchWhere searchWhere = new MoFlightSearchWhere();
        searchWhere.DepDate="2022-04-23";
        searchWhere.DstAirport="PEK";
        searchWhere.OrgAirport="SHA";
        request.GoSearchWhere =searchWhere;

        request.TripType =1;
        request.hasKeyCustomers=true;
//        request.carrier="CA";
        request.accountCode="0100001";
        request.hasKeyCustomers=false;

        /*MoFlightSearchResponse response = linkStar._FlightSearch(request);
        System.out.println(response);*/


        //往返
       /* MoFlightSearchWhere searchWhere = new MoFlightSearchWhere();
        searchWhere.DepDate="2022-03-01";
        searchWhere.DstAirport="PEK";
        searchWhere.OrgAirport="SHA";
        request.GoSearchWhere =searchWhere;


        MoFlightSearchWhere searchWhereBack = new MoFlightSearchWhere();
        searchWhereBack.DepDate="2022-03-09";
        searchWhereBack.DstAirport="SHA";
        searchWhereBack.OrgAirport="PEK";
        request.BackSearchWhere =searchWhereBack;
        request.hasKeyCustomers=false;

        request.TripType =2;
        linkStar._FlightSearch(request);*/






        //实时仓位(单程)
        /*MoFlightSearchWhere searchWhere = new MoFlightSearchWhere();
        searchWhere.DepDate="2021-11-29";
        searchWhere.DstAirport="CAN";
        searchWhere.OrgAirport="WUH";
        searchWhere.carrier="CZ";
        searchWhere.FlightNo="8672";
        request.GoSearchWhere =searchWhere;

        request.TripType =1;
        linkStar.realTimeFlightCheck(request);*/

        //实时仓位(往返)
        /*MoFlightSearchWhere searchWhere = new MoFlightSearchWhere();
        searchWhere.DepDate="2021-11-29";
        searchWhere.DstAirport="CAN";
        searchWhere.OrgAirport="WUH";
        searchWhere.carrier="CZ";
        searchWhere.FlightNo="8672";


        MoFlightSearchWhere back = new MoFlightSearchWhere();
        back.DepDate="2021-12-06";
        back.DstAirport="WUH";
        back.OrgAirport="CAN";
        back.carrier="CZ";
        back.FlightNo="8671";


        request.GoSearchWhere =searchWhere;
        request.BackSearchWhere = back;

        request.TripType =2;
        linkStar.realTimeFlightCheck(request);
*/




       //航班详情
        /*linkStar.searchFightDetails("2021-12-10","1831","Y",
                "CA","PEK","SHA");*/



        //PNR预定

        //单程
       /*MoCreateOrderRequest moRequest = new MoCreateOrderRequest();

        MoSegment moSegment = new MoSegment();
        moSegment.ArrDate= convertToDate("2021-12-20 21:20:00","yyyy-MM-dd HH:mm:ss");
        moSegment.DepDate = convertToDate("2021-12-20 18:55:00","yyyy-MM-dd HH:mm:ss");
        moSegment.FlightNo="8363";
        moSegment.Airline ="CA";
        moSegment.DstAirport="PKX";
        moSegment.OrgAirport="SHA";
        moSegment.Cabin="Y";
        moSegment.PlaneStyle="73K";

        MoPassenger passenger = new MoPassenger();
        passenger.PassengerName="张学友";
        passenger.Sex=true;
        passenger.IDType=1;
        passenger.IDNO = "120221197001011150";
        passenger.PassengerMobile="17610641000";
        moRequest.ListMoPassenger.add(passenger);

        MoPassenger passenger1 = new MoPassenger();
        passenger1.PassengerName="张伟";
        passenger1.Sex=true;
        passenger1.IDType=1;
        passenger1.PassengerType = 2;
        passenger1.IDNO = "31010420080101573X";
        passenger1.PassengerMobile="17610641000";
        moRequest.ListMoPassenger.add(passenger1);



        moRequest.TripType=1;


        moRequest.ListGoSegment.add(moSegment);

        linkStar._OrderCreate(moRequest);*/



       //往返
       /* MoCreateOrderRequest moRequest = new MoCreateOrderRequest();

        MoSegment moSegment = new MoSegment();
        moSegment.ArrDate= convertToDate("2021-12-12 21:20:00","yyyy-MM-dd HH:mm:ss");
        moSegment.DepDate = convertToDate("2021-12-12 18:55:00","yyyy-MM-dd HH:mm:ss");
        moSegment.FlightNo="8363";
        moSegment.Airline ="CA";
        moSegment.DstAirport="PKX";
        moSegment.OrgAirport="SHA";
        moSegment.Cabin="Y";
        moSegment.PlaneStyle="73K";

        MoPassenger passenger = new MoPassenger();
        passenger.PassengerName="刘备";
        passenger.Sex=true;
        passenger.IDType=1;
        passenger.IDNO = "120221197001011150";
        passenger.PassengerMobile="17610641000";

        moRequest.ListMoPassenger.add(passenger);

        moRequest.TripType=2;


        moRequest.ListGoSegment.add(moSegment);


        MoSegment backMoSegment = new MoSegment();
        backMoSegment.ArrDate= convertToDate("2021-12-23 20:55:00","yyyy-MM-dd HH:mm:ss");
        backMoSegment.DepDate = convertToDate("2021-12-23 18:30:00","yyyy-MM-dd HH:mm:ss");
        backMoSegment.FlightNo="1885";
        backMoSegment.Airline ="CA";
        backMoSegment.DstAirport="SHA";
        backMoSegment.OrgAirport="PKX";
        backMoSegment.Cabin="Y";
        backMoSegment.PlaneStyle="773";
        moRequest.ListBackSegment.add(backMoSegment);


        linkStar._OrderCreate(moRequest);*/


        //PNR结果信息提取
        //单程
//        MoQueryOrderRequest moRequest = new MoQueryOrderRequest();
//        moRequest.OrderID="JZFP0W";
//
//        linkStar._QueryOrderInfo(moRequest);



        //取消PRN
        /*MoCancelOrderRequest orderRequest = new MoCancelOrderRequest();
        MoOrderItem  item = new MoOrderItem();
        item.OrderID = "JGW16V";
        orderRequest.ListOrderItem.add(item);

        linkStar._CancelOrder(orderRequest);*/


        //出票
       /* MoOrderPayRequest orderPayRequest = new MoOrderPayRequest();
        orderPayRequest.OrderID="JGW189";
        linkStar._OrderPay(orderPayRequest);*/


       //运价
       /* FlightPublishPriceReqVo reqVo = new FlightPublishPriceReqVo();
        reqVo.setPassengerType(1);
        reqVo.setDepDate("2021-12-12");
        reqVo.setAirlineCode("MU");
        reqVo.setDstAirport("PEK");
        reqVo.setOrgAirport("SHA");

        linkStar.publishPrice(reqVo);*/


        /*String birthByIdCard = IDCardUtil.getBirthFormatByIdCard("140728199808160055");
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        System.out.println(dateFormat.parse(birthByIdCard));*/


        //linkStar.autoRefundTicket("822-6973668665");

        //FlightPublishPriceReqVo reqVo=new FlightPublishPriceReqVo();

        MoOrderRefundRequest refundRequest=new MoOrderRefundRequest();
        refundRequest.OrderID="822-6973668801";
        //linkStar._OrderRefund(refundRequest);

        /*MoQueryOrderRequest request=new MoQueryOrderRequest();
        request.OrderID="HYEJPP";
        linkStar._QueryOrderInfo(request);*/


        //linkStar.calculationFreight("HRJ5B2");




        //改签航班查询
       /* ChangeFlightRequest request=new ChangeFlightRequest();
        request.setAirEquipType("33L");
        request.setAirline("KN");
        request.setTicketNo("822-6974947009");
        request.setCabin("Y");
        request.setOrgAirport("PKX");
        request.setDstAirport("SHA");
        request.setDepartureTime("2022-03-03 07:10:00");

        linkStar.changeSearchFlight(request);*/



       //国内公布运价


        /*FlightPublishPriceReqVo reqVo = new FlightPublishPriceReqVo();
        reqVo.setOrgAirport("PKX");
        reqVo.setDstAirport("SHA");
        reqVo.setAirlineCode("KN");
        reqVo.setPassengerType(1);
        reqVo.setDepDate("2022-03-01T07:10:00");

        linkStar.publishPrice(reqVo);*/


        //linkStar._GetCabinTgq(new MoCabinTgqRequest());

        //linkStar.ticketInfo("JQFXGZ");






    }


    public static Date convertToDate(String str, String pattern){
        SimpleDateFormat sdf=new SimpleDateFormat(pattern);
        Date date=null;
        if(str!=null){
            try {
                date=sdf.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return date;
    }
}
